<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
	<title>Cadastro de Clientes</title>
</h:head>
<ui:composition template="templatePrincipal.xhtml">
	<ui:define name="header">
		<ui:include src="header.xhtml" />
	</ui:define>
	<ui:define name="centro">
		<h:body>
			<p:growl id="messages" showDetail="true" life="1000" />
			<p:confirmDialog id="confirmRemoveDialog"
				message="Remover o cliente ?" header="Remoção de cliente"
				severity="alert" widgetVar="confirmation" appendToBody="true"
				update="messages">
				<p:commandButton id="confirm" value="Sim"
					oncomplete="confirmation.hide()"
					actionListener="#{clienteController.removeCliente}"
					update="messages,form1:tabview1:dataTable,form1:tabview1:dados" />
				<p:commandButton id="decline" value="Não"
					onclick="confirmation.hide()" type="button" />
			</p:confirmDialog>
			<h:form id="form1" prependId="false">
				<p:tabView id="tabview1" dynamic="true" cache="false">
					<p:ajax event="tabChange"
						listener="#{clienteController.changeTabView}" update="novocli" />
					<p:tab id="tabpesq" title="Pesquisar">
						<p:panel header="Clientes">
							<p:panelGrid id="dados" columns="8">
								<f:facet name="header">
        						Dados da pesquisa
    						</f:facet>
								<p:outputLabel for="pesqproponente" value="Nome :" />
								<p:inputText id="pesqproponente"
									value="#{clienteController.pesqcliente.proponente}" />
								<p:outputLabel for="pesqemail" value="Email :" />
								<p:inputText id="pesqemail"
									value="#{clienteController.pesqcliente.email}" />
								<p:outputLabel for="pesqcpf" value="CPF :" />
								<p:inputText id="pesqcpf"
									value="#{clienteController.pesqcliente.cpf}" />
								<p:outputLabel for="pesqtelcel" value="Celular :" />
								<p:inputText id="pesqtelcel"
									value="#{clienteController.pesqcliente.telCelular}" />
								<p:outputLabel for="pesqtelcomercial" value="Tel. Comercial :" />
								<p:inputText id="pesqtelcomercial"
									value="#{clienteController.pesqcliente.telComercial}" />
								<p:outputLabel for="pesqconjuge" value="Conjuge :" />
								<p:inputText id="pesqconjuge"
									value="#{clienteController.pesqcliente.conjuge}" />
								<p:outputLabel for="pesqcpfconj" value="CPF Conjuge :" />
								<p:inputText id="pesqcpfconj"
									value="#{clienteController.pesqcliente.cpfConjuge}" />
								<p:outputLabel for="pesqemailconj" value="Email Conjuge :" />
								<p:inputText id="pesqemailconj"
									value="#{clienteController.pesqcliente.emailConjuge}" />
								<p:outputLabel for="pesqtelcelconj" value="Cel. Conjuge :" />
								<p:inputText id="pesqtelcelconj"
									value="#{clienteController.pesqcliente.telCelularConj}" />
								<p:outputLabel for="pesqtelcomconj" value="Tel. Comm. Conjuge :" />
								<p:inputText id="pesqtelcomconj"
									value="#{clienteController.pesqcliente.telComercialConj}" />
								<p:outputLabel for="pesqresidencia" value="Endereço :" />
								<p:inputText id="pesqresidencia"
									value="#{clienteController.pesqcliente.residencia}" />
								<p:commandButton value="Pesquisar"
									actionListener="#{clienteController.pegarTodosClientes}"
									update="dataTable,dados" />
							</p:panelGrid>
							<p:dataTable id="dataTable" var="cliente"
								value="#{clienteController.clienteList}" paginator="true"
								rows="3"
								paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
								rowsPerPageTemplate="3,6,9"
								selection="#{clienteController.rescliente}"
								selectionMode="single" rowKey="#{cliente.id}">
								<p:ajax event="rowSelect"
									listener="#{clienteController.rowSelect}"
									update=":form1:tabview1:dados,:form1:tabview1:dataTableImoveis" />
								<f:facet name="header">
            					Clientes encontrados
        					</f:facet>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Nome" />
									</f:facet>
									<h:outputText value="#{cliente.proponente}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Email" />
									</f:facet>
									<h:outputText value="#{cliente.email}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="CPF" />
									</f:facet>
									<h:outputText value="#{cliente.cpf}" />
								</p:column>
							</p:dataTable>
							<p:commandButton value="Remover" onclick="confirmation.show()"
								type="button" />
							<p:commandButton value="Salvar"
								actionListener="#{clienteController.saveCliente}"
								update="dados,dataTable,:messages" />
							<p:commandButton value="Cancelar" type="reset" />
						</p:panel>
						<p:panel header="Imoveis">
							<p:dataTable id="dataTableImoveis" var="imovel"
								value="#{clienteController.rescliente.imoveis}" paginator="true"
								rows="3"
								paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
								rowsPerPageTemplate="3,6,9"
								selection="#{clienteController.selectedImovel}"
								selectionMode="single" rowKey="#{imovel.id_imovel}">
								<f:facet name="header">
            						Lista de Imoveis do cliente
        						</f:facet>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Endereço" />
									</f:facet>
									<p:inputText value="#{imovel.endereco}" size="20" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Mat." />
									</f:facet>
									<p:inputText value="#{imovel.matricula}" size="5" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Rec. Próprios" />
									</f:facet>
									<p:inputText value="#{imovel.recursosprop}" size="10" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Fnd. Garantia" />
									</f:facet>
									<p:inputText value="#{imovel.fundogarantia}" size="10" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Val. Financ" />
									</f:facet>
									<p:inputText value="#{imovel.valorfinanc}" size="10" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Val. Avaliação" />
									</f:facet>
									<p:inputText value="#{imovel.valoraval}" size="10" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Gar." />
									</f:facet>
									<p:selectBooleanCheckbox value="#{imovel.garagem}" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Val.Vnd. Gar." />
									</f:facet>
									<p:inputText value="#{imovel.valorcompvendagaragem}" size="10" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Val. Vnd Apto." />
									</f:facet>
									<p:inputText value="#{imovel.valcompvendaapto}" size="10" />
								</p:column>
								<p:column>
									<f:facet name="header">
										<h:outputText value="Val. Vnd Total" />
									</f:facet>
									<p:inputText value="#{imovel.valcompvendatotal}" size="10" />
								</p:column>
							</p:dataTable>
							<p:commandButton id="insereImovelbnt" value="Adiciona Imovel"
								actionListener="#{clienteController.adicionaImovel}"
								update="dataTableImoveis,:messages" />
							<p:commandButton id="removeImovelbnt" value="Remove Imovel"
								actionListener="#{clienteController.removeImovel}"
								update="dataTableImoveis,:messages" />
						</p:panel>
					</p:tab>
					<p:tab id="tabnovocli" title="Novo Cliente">
						<p:panelGrid id="novocli" columns="8">
							<f:facet name="header">
        					Dados do cliente
    					</f:facet>
							<p:outputLabel for="proponente" value="Nome :" />
							<p:inputText id="proponente"
								value="#{clienteController.cliente.proponente}" />
							<p:outputLabel for="email" value="Email :" />
							<p:inputText id="email"
								value="#{clienteController.cliente.email}" />
							<p:outputLabel for="cpf" value="CPF :" />
							<p:inputText id="cpf" value="#{clienteController.cliente.cpf}" />

							<p:outputLabel for="novotelcel" value="Celular :" />
							<p:inputText id="novotelcel"
								value="#{clienteController.cliente.telCelular}" />
							
							<p:outputLabel for="novotelcomercial" value="Tel. Comercial :" />
							<p:inputText id="novotelcomercial"
								value="#{clienteController.cliente.telComercial}" />
							
							<p:outputLabel for="novoconjuge" value="Conjuge :" />
							<p:inputText id="novoconjuge"
								value="#{clienteController.cliente.conjuge}" />
							
							<p:outputLabel for="novocpfconj" value="CPF Conjuge :" />
							<p:inputText id="novocpfconj"
								value="#{clienteController.cliente.cpfConjuge}" />
							
							<p:outputLabel for="novoemailconj" value="Email Conjuge :" />
							<p:inputText id="novoemailconj"
								value="#{clienteController.cliente.emailConjuge}" />
								
							<p:outputLabel for="novotelcelconj" value="Cel. Conjuge :" />
							<p:inputText id="novotelcelconj"
								value="#{clienteController.cliente.telCelularConj}" />
							
							<p:outputLabel for="novotelcomconj" value="Tel. Comm. Conjuge :" />
							<p:inputText id="novotelcomconj"
								value="#{clienteController.cliente.telComercialConj}" />
								
							<p:outputLabel for="novoresidencia" value="Endereço :" />
							<p:inputText id="novoresidencia"
								value="#{clienteController.cliente.residencia}" />

							<p:commandButton value="Salvar"
								actionListener="#{clienteController.createCliente}"
								update="novocli,:messages" />
							<p:commandButton value="Cancelar" type="reset" />
						</p:panelGrid>
					</p:tab>
					<p:tab tab="importar" title="Importar">
						<p:panelGrid>
							<h:outputText value="Desenvolvimento futuro" />
						</p:panelGrid>
					</p:tab>
				</p:tabView>
			</h:form>
		</h:body>
	</ui:define>
</ui:composition>
</html>